<admintpl file="header" />
<script type="text/javascript">
	
</script>
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('news/notice')}">通知公告</a></li>
			<li class="active"><a href="{:U('news/addnotice')}">添加公告</a></li>
		</ul>
		<form method="post" class="form-horizontal" action="{:U('News/addnotice_post')}">
            <div class="form-group">
                <label class="col-md-2 control-label">标题<span class="required" aria-required="true"> * </span></label>
                <div class="col-md-6">
                    <input type="hidden" name="type" value="2">
                    <input type="text" name="title" required />
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-md-2 control-label">内容</label>
                <div class="col-md-8">
                    <script type="text/plain" id="content" name="content"></script>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">来源</label>
                <div class="col-md-6">
                    <input type="text" name="source">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">附件</label>
                <div class="controls">
                    <a class="btn upBtn btn-primary" href="javascript:void(0);">上传</a>
                    <input type="file" id="upFile" name="upFile" style="display:none" />
                </div>
            </div>
			<div class="form-actions col-md-10 col-md-offset-2">
				<button type="submit" class="btn btn-primary js-ajax-submit">{:L('ADD')}</button>
				<a class="btn btn-default" href="javascript:history.back(-1);">{:L('BACK')}</a>
			</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
		//编辑器路径定义
		var editorURL = GV.WEB_ROOT;
	</script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript">
        /*
         * 多文件上传
         * @param reqUrl 请求地址
         * @param folder 上传后存储文件夹
         **/
   
        function UploadFile(reqUrl, folder){
            if($("#upFile").val() == ""){
                alert("请选择待上传文件！");
                return false;
            }
            $.ajaxFileUpload({
                url : reqUrl,
                secureuri : false, //安全协议
                fileElementId:'upFile', //id
                type : 'post',
                dataType : 'json',
                data:{
                    'folder'   : folder,
                    'ajax': 1
                },
                async : false,
                error : function(data,status,e) {
                    alert("服务器内部错误！");
                },
                success : function(json){
                    if (json.rtnType == 'T'){
                    	var Cts = "HAIHUI" + json.file_type;
						if(Cts.indexOf("image") > 0 ||  Cts.indexOf("pdf") > 0){
	                            html = "<div class='controls' style='margin-top:10px;margin-left:220px'>   \n"
	                                + " <input type='hidden' name='filePath[]' value='"+json.rtnResult+"' />    \n"
	                                + " <input type='hidden' name='fileName[]' value='"+json.file_name+"' />    \n"
	                                + " <input type='hidden' name='file_size[]' value='"+json.file_size+"' />   \n"
	                                + " <input type='hidden' name='postfix[]' value='"+json.postfix+"' />     \n"
	                                + " <a href='#' target='_blank'><label class=\"fileDownload\" path=\""+json.rtnResult+"\" name=\""+json.file_name+"\">"+json.file_name+"</label></a>\n"
	                                + " <a href="+json.rtnResult+" target='_blank' class='btn btn-warning btn-xs'>查看</a>\n"
	                                + " <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile'>删除</a> \n"
	                                + "</div>";
	                            $(".controls:last").after(html);
	                        }else{
	                        	html = "<div class='controls' style='margin-top:10px;margin-left:220px'>   \n"
	                                + " <input type='hidden' name='filePath[]' value='"+json.rtnResult+"' />    \n"
	                                + " <input type='hidden' name='fileName[]' value='"+json.file_name+"' />    \n"
	                                + " <input type='hidden' name='file_size[]' value='"+json.file_size+"' />   \n"
	                                + " <input type='hidden' name='postfix[]' value='"+json.postfix+"' />     \n"
	                                + " <a href='#' target='_blank'><label class=\"fileDownload\" path=\""+json.rtnResult+"\" name=\""+json.file_name+"\">"+json.file_name+"</label></a>\n"
	                                + " <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile'>删除</a> \n"
	                                + "</div>";
	                            $(".controls:last").after(html);
	                        }
                        }
                },
                complete: function(xmlHttpRequest) {
                
                    $("#upFile").replaceWith('<input type="file" id="upFile" name="upFile" style="display:none" />');
                    $("#upFile").on("change", function(){
                        UploadFile(reqUrl, folder);
                    });
                }
            });
        }

        
        $(function () {
            $("form input").addClass("form-control");
        })
        var editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        $(document).ready(function(e) {
            // 选择图片
            $(document).on("click", ".upBtn", function(e) {
                $("#upFile").click();
            });
            // 文件选择器change事件
            $("#upFile").on("change", function(){
                UploadFile("{:U('News/upload')}", "new_notice");
            });
            $(document).on("click", ".delFile", function(){
                if($(this).attr("value") != undefined){
                    delFile("{:U('News/delFile')}", $(this).attr("value"), $(this))
                } else {
                    $(this).closest("div").remove();
                }
            });
            // 拼接一行
            $(".addLine").click(function(){
                var html =  "<tr>" +
                            "   <td><input type=\"text\" name=\"job_name[]\" /></td>" +
                            "   <td><input type=\"text\" name=\"this_week_count[]\" /></td>" +
                            "   <td><input type=\"text\" name=\"next_week_count[]\" /></td>" +
                            "   <td>" +
                            "       <input type=\"hidden\" name=\"plan_type[]\" value=\""+$(this).attr("type")+"\" >" +
                            "       <a class=\"btn delLine\" href=\"javascript:void(0);\">删除</a>" +
                            "   </td>" +
                            "</tr>";
                $(this).closest("thead").next().append(html);
            });
            // 删除一行
            $(document).on("click", ".delLine", function(){
                $(this).closest("tr").remove();
            });
        });
    </script>
</body>
</html>